from src.game.entity.entity import Entity

import pygame


class EntityFX(Entity):
    
    name = "entityparticle"
    
    def __init__(self):
        Entity.__init__(self)
        self.lifetime = 100
        self.age = 0
        self.target = None
        self.collision = False
        self.width = 0.1
        self.height = 0.1
        self.sprite = pygame.Surface((10, 10))
        
    def render(self,client,viewport):
        x, y = viewport.globalToLocale(self.x, self.y)
        client.window.surface.blit(self.sprite, (x * 64, y * 64))
    
    def update(self):
        Entity.update(self)
        if self.age >= self.lifetime:
            self.world.despawnEntity(self)
        else:
            self.age += 1
        
                 
    def readFromPSO(self, pso):
        Entity.readFromPSO(self, pso)
        self.lifetime = pso.get("lifetime")
        self.age = pso.get("age")

    def writeToPSO(self, pso):
        Entity.writeToPSO(self, pso)
        pso.set("lifetime", self.lifetime)
        pso.set("age", self.age)
            
            